<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>任课老师审批页面</title>
    <style type="text/css">
        xy-td {
            justify-content: center;
        }
    </style>

    <script charset="utf-8" src="../tools/jquery-3.6.0.min.js" type="text/javascript"></script>
</head>
<body>
<script type="module">
    import '../xy-ui/index.js';
</script>

<!--学生提交申请后的那个状态的请假信息才会显示到这里-->
<!--当前登录老师所需要处理的请假信息-->
<xy-table thead="请假编号,学号,姓名,请假课程,请假时段,请假原因,操作">
    <xy-tr th:each="item:${list}">
        <xy-td th:text="${item.leId}"></xy-td>
        <xy-td th:text="${item.id}"></xy-td>
        <xy-td th:text="${item.name}"></xy-td>
        <xy-td th:text="${item.course}"></xy-td>
        <xy-td th:text="${item.duringDate}"></xy-td>
        <xy-td th:text="${item.reason}"></xy-td>
        <xy-td>
            <xy-button th:key="${item.leId}">通过</xy-button>
            <xy-button th:key="${item.leId}" type="danger">不通过</xy-button>
        </xy-td>
    </xy-tr>

</xy-table>

<script type="text/javascript">

    $("xy-button:nth-child(1)").click(function (e) {
        let leId = e.currentTarget.attributes.key.value;
        $.get('/teacher/approve/' + leId + '/1', function (res) {
            XyMessage.success('审核通过');
            // 延迟2秒刷新
            setTimeout(function () {
                window.location.reload();
            }, 2000);
        })
    });

    $("xy-button[type='danger']").click(function (e) {
        let leId = e.currentTarget.attributes.key.value;
        XyDialog.prompt({
            title: '请输入不通过原因',
            oktext: '确认',
            ok: function (value) {
                console.log(value);
                $.get('/teacher/approve/' + leId + '/2', {mark: value}, function (res) {
                    XyMessage.info('审核不通过');
                    // 延迟2秒刷新
                    setTimeout(function () {
                        window.location.reload();
                    }, 2000);
                })
            },
            cancel: function () {
            }
        });
    })

</script>
</body>
</html>
